// pages/sign_up/sign_up.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userName: '',
    userTel: '',
    sign_zt:'',
    display:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    that.setData({
      qsid: options.qsid,
      huodongid: options.huodongid,
      hdname: options.hdname,
      hdmoney: options.hdmoney,
      hdcont1: options.hdcont1,
      hdcont2: options.hdcont2,
    })
    
  },
  userNameInput: function (e) {
    this.setData({
      userName: e.detail.value
    })
  },
  userTelInput: function (e) {
    this.setData({
      
      userTel: e.detail.value
    })
  },
  signupClick: function (e) {
    var that=this;
    if (that.data.userName == ""){
      that.setData({
        sign_zt:'姓名不能为空',
        display: true,
      })
      setTimeout(function () {
        that.setData({
          display: false,
        })
      }, 1000)
    } else if (that.data.userName.length<2){
      that.setData({
        sign_zt: '姓名格式不正确',
        display: true,
      })
      setTimeout(function () {
        that.setData({
          display: false,
        })
      }, 1000)
    } else if (that.data.userTel == ""){
      that.setData({
        sign_zt: '电话不能为空',
        display: true,
      })
      setTimeout(function () {
        that.setData({
          display: false,
        })
      }, 1000)
    } else if (that.data.userTel.length<11) {
      that.setData({
        sign_zt: '电话格式不正确',
        display: true,
      })
      setTimeout(function () {
        that.setData({
          display: false,
        })
      }, 1000)
    } else if (!(/^1[34578]\d{9}$/.test(that.data.userTel))) {
      that.setData({
        sign_zt: '电话格式不正确',
        display: true,
      })
      setTimeout(function () {
        that.setData({
          display: false,
        })
      }, 1000)
    }else{
      var xm = that.data.userName;
      var dh = that.data.userTel;
      var hdid = that.data.huodongid;
      var qsid = that.data.qsid;
      wx.showLoading({
        title: '加载中',
      })

      wx.request({
        url: 'https://miniapp.odeman.com/summercamp/extension.php?xm=' + xm +'&dh=' + dh + '&itemid=' +hdid + '&qsid=' + qsid,
        header: {
          'Content-Type': 'application/json'
        },
        success: function (res) {
          wx.hideLoading()

          that.setData({
            sign_zt: "报名成功",
            display: true,
          })
          setTimeout(function () {
            that.setData({
              display: false,
            })
            wx.navigateBack({
              delta: 1
            })
          }, 1000)
          
        }
      })
     
    }
  },
  qxClick:function(){
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})